<template>
    <div>	 
      	<header class="classification_t header_fixed" id="title">
          <div class="classification_t_l" @click="goPrev">
                <img src="./../../assets/images/return.png" width="30%">
          </div>
          <div class="classification_t_r">{{$route.meta.title}}</div>
        </header>
        <div class="personal_information_nickname1" style="margin-top:50px;">
            <div class="p_i_nickname_l1">联系人</div>
            <div class="p_i_nickname_r1">
                <input type="text" placeholder="请填写姓名" v-model="param.linkman">
            </div>
        </div>
        <div class="personal_information_nickname1">
            <div class="p_i_nickname_l1">联系方式</div>
            <div class="p_i_nickname_r1">
                <input type="tel" placeholder="请填写手机号" v-model="param.phone">
            </div>
        </div>
        <div class="personal_information_nickname1" @click="openPositioning">
            <div class="p_i_nickname_l1">所在地区</div>
            <div class="addadres_icon_box">
                <input class="addadres_icon_box_l" type="text" placeholder="省，市，区" v-model="param.address" disabled="disabled" style="font-size: 14px; padding-left: 10px;">
                <div class="addadres_icon_box_r"><img src="@/assets/images/addadres_icon.png"></div>
            </div>
        </div>
        <div class="personal_information_nickname1">
            <div class="p_i_nickname_l1">地址</div>
            <div class="p_i_nickname_r1">
                <input type="text" placeholder="请输入详细地址" v-model="param.address_detail">
            </div>
        </div>
        <div class="index_divide"></div>
        <div class="index_divide"></div>
        <div class="update_btn" @click="doUpdateadress">
            <input type="submit" value="修改">
        </div>	
    </div>
</template>
<script>
// import TopWithBack from './../common/TopWithBack'
import { updateAdress } from '@/api/allapis'
// import { Message, MessageBox, Loading } from 'element-ui'
export default{
  name: 'Addadress',
  data(){
    return{
      param:{
        address_id:'',
        linkman:'',
        phone:'',
        add_lon:'',
        add_lat:'',
        address:'',
        adcode:'',
        address_detail:'',
      },
      item:'',//接收到的地址对象
    }
  },
  // components:{
  //     TopWithBack
  // },
  methods:{
      //打开地图定位页面
      openPositioning(){
        // console.log(JSON.stringify(this.param))
          this.$router.replace({
            name:'Map',
            params:{
              param:this.param, //需要传到地图的数据，避免从地图返回时填写的数据消失
            },
            query:{
              gotomap:'1'//gotomap为一是表示是从修改地址页面跳转过来的
            }
          })
      },
      //更改地址
      doUpdateadress(){
        if (this.param.linkman == '') {
              this.$vux.toast.show({
                text: '请输入您的姓名',
                type: 'warn',
                time: 800,
              })
              return;
          }
          if (this.param.phone == '') {
              this.$vux.toast.show({
                text: '请输入您的手机号',
                type: 'warn',
                time: 800,
              })
              return;
          }
          if (!(/^1[3|4|5|8]\d{9}$/.test(this.param.phone))) {
              this.$vux.toast.show({
                text: '手机号有误，请重新输入！',
                type: 'warn',
                time: 800,
              })
              return;
          }
          if (this.param.address_detail == '') {
              this.$vux.toast.show({
                text: '请输入详细的地址',
                type: 'warn',
                time: 800,
              })
              return;
          }
          // console.log(JSON.stringify(this.item.location.P))
         
          console.log(JSON.stringify(this.param))
          const self = this
          updateAdress(this.param).then(response=>{
              this.$vux.toast.show({
                text: '修改成功',
                type: 'success',
                time: 800,
                onHide: function () {
                  // self.$router.replace({
                  //   name:'Adresses'
                  // })
                  self.$router.go(-1)
                }
              })
          })
      },
      goPrev(){
        // this.$router.replace({
        //   name:'Adresses'
        // })
        this.$router.go(-1)
      },
  },
  mounted(){
      try {
        if(this.$route.params.resonseparam){//从地图页面回传过来的数据
          this.param.address_id = this.$route.params.resonseparam.address_id
          // console.log(JSON.stringify(this.$route.params.resonseparam))
          this.param.linkman = this.$route.params.resonseparam.linkman
          this.param.phone = this.$route.params.resonseparam.phone
          this.param.add_lon = this.$route.params.resonseparam.add_lon
          this.param.add_lat = this.$route.params.resonseparam.add_lat
          this.param.address = this.$route.params.resonseparam.address
          this.param.adcode = this.$route.params.resonseparam.adcode
          this.param.address_detail = this.$route.params.resonseparam.address_detail
            // console.log(JSON.stringify(this.param))
        }
        if(this.$route.params.adressitem){//从地址页面传过来的数据
          // this.param = this.$route.params.adressitem
          this.param.address_id = this.$route.params.adressitem.id
          // console.log(JSON.stringify(this.param.address_id))
          this.param.linkman = this.$route.params.adressitem.linkman
          this.param.phone = this.$route.params.adressitem.phone
          this.param.add_lon = this.$route.params.adressitem.add_lon
          this.param.add_lat = this.$route.params.adressitem.add_lat
          this.param.address = this.$route.params.adressitem.address
          this.param.adcode = this.$route.params.adressitem.adcode
          this.param.address_detail = this.$route.params.adressitem.address_detail
          // console.log(JSON.stringify(this.param))
        }
      } catch (error) {
      }
  },
}
</script>
<style>

</style>


